﻿function OpenLogin() {
    $('#pageDimmerLogin').fadeIn(400);
    $('#msgboxLogin').fadeIn(400);
    return false;
}

function CloseLogin() {
    $('#pageDimmerLogin').fadeOut(100);
    $('#msgboxLogin').fadeOut(100);
}

function OpenRegister() {
    $('#pageDimmerLogin').fadeOut(100);
    $('#msgboxLogin').fadeOut(100);

    $('#pageDimmerRegister').fadeIn(400);
    $('#msgboxRegister').fadeIn(400);
}

function CloseRegister() {
    $('#pageDimmerRegister').fadeOut(100);
    $('#msgboxRegister').fadeOut(100);
}

var tempsearch = '0';
function ClickSearch() {
    if (tempsearch == '0') {
        $('#resultsearch').css('display', 'block');
        $('#iconsearch').css('display', 'none');
        $('#iconsearchcancel').css('display', 'block');
        tempsearch = '1';
    }
    else {
        $('#resultsearch').css('display', 'none');
        $('#iconsearch').css('display', 'block');
        $('#iconsearchcancel').css('display', 'none');
        tempsearch = '0';
    }
}

function ShowCategory(num) {
    if (num == '1') {
        $('#menucategory').css('display', 'block');
    }
    else if(num == '0'){
        $('#menucategory').css('display', 'none');
    }
}

$(window).scroll(function (e) {
    var scroller_anchor = $(".scroller_anchor").offset().top;

    if ($(this).scrollTop() >= scroller_anchor && $('.MenuTop').css('position') != 'fixed') {
        $('.MenuTop').css({ 'position': 'fixed', 'top': '0px' });
        $('.scroller_anchor').css('height', '2px');
        $('#menudefault').css('display', 'none');
        $('#menuscroll').css('display', 'block');
    }
    else if ($(this).scrollTop() < scroller_anchor && $('.scroller').css('position') != 'relative') {
        $('.scroller_anchor').css('height', '0px');
        $('.MenuTop').css({ 'position': 'relative' });
        $('#menudefault').css('display', 'block');
        $('#menuscroll').css('display', 'none');
    }
});

$(document).ready(function () {
    if (!Modernizr.input.placeholder) {

        $('[placeholder]').focus(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                //input.removeClass('placeholder');
            }
        }).blur(function () {
            var input = $(this);
            if (input.val() == '' || input.val() == input.attr('placeholder')) {
                //input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur();
        $('[placeholder]').parents('form').submit(function () {
            $(this).find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            })
        });
    }
});

function RegisterEmail() {
    var emailinput = $("#email").val();

    if (emailinput == null || emailinput == '') {
        alert("Input Email.");
        document.getElementById('email').focus();
        return false;
    }

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(emailinput)) {
        alert("Email is not Correct.");
        $("#email").val('');
        document.getElementById('email').focus();
        return false;
    }

    $.ajax({
        type: "POST",
        url: "GetCode.aspx",
        data: "MODE=1&emailinput=" + emailinput,
        cache: false,
        success: KM_CallbackRegisterEmail,
        dataType: "text"
    });
}

function KM_CallbackRegisterEmail(res) {
    var obj = JSON.parse(res);
    if (obj[0][0] == 1)
        alert("Sent Email Successfull!");
    else
        alert("Error.");
}

function keypress(e) {
    var keypressed = null;
    if (window.event) {
        keypressed = window.event.keyCode; //IE
    }
    else {
        keypressed = e.which; //NON-IE, Standard
    }

    if (keypressed < 48 || keypressed > 57) { //CharCode của 0 là 48 (Theo bảng mã ASCII)
        //CharCode của 9 là 57 (Theo bảng mã ASCII)
        if (keypressed == 8 || keypressed == 127) {//Phím Delete và Phím Back
            return;
        }
        return false;
    }
}
